<!DOCTYPE html>
<html lang="zh-cn">
<head>
  <meta charset="utf-8"/>
  <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
  <meta name="renderer" content="webkit"/>
  <title>获取百度BDUSS</title>
  <link href="//cdn.staticfile.org/twitter-bootstrap/3.4.1/css/bootstrap.min.css" rel="stylesheet"/>
  <script src="//cdn.staticfile.org/jquery/1.12.4/jquery.min.js"></script>
  <script src="//cdn.staticfile.org/twitter-bootstrap/3.4.1/js/bootstrap.min.js"></script>
  <!--[if lt IE 9]>
    <script src="//cdn.staticfile.org/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="//cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
  <![endif]-->
</head>
<body>
<div class="container">
<div class="col-xs-12 col-sm-10 col-md-8 col-lg-6 center-block" style="float: none;">
<div class="panel panel-primary">
	<div class="panel-heading" style="text-align: center;"><h3 class="panel-title">
		获取百度BDUSS
	</div>
	<div class="panel-body" style="text-align: center;">
		<div class="list-group">
		<ul class="nav nav-tabs">
			<li><a href="index.html">普通登录</a></li><li class="active"><a href="index2.html">扫码登录</a></li><li><a href="index3.html">短信验证码登录</a></li><li><a href="index4.html">第三方登录</a></li>
		</ul>
			<div class="list-group-item"><img src="https://m.baidu.com/static/index/plus/plus_logo.png" width="160px"></div>
			<div class="list-group-item list-group-item-info" style="font-weight: bold;" id="load">
				<span id="loginmsg">正在加载</span><span id="loginload" style="padding-left: 10px;color: #790909;">.</span>
			</div>
			<div class="list-group-item" id="login" style="display:none;">
			<div class="list-group-item" id="qrimg">
			</div>
			<div class="list-group-item" id="mobile" style="display:none;"><button type="button" id="mlogin" onclick="mloginurl()" class="btn btn-warning btn-block">跳转百度APP登录</button><br/><button type="button" onclick="qrlogin()" class="btn btn-success btn-block">我已完成登录</button></div>
			</div>
			<br/><a href="./index2.html">点此重新登录</a>
		</div>
	</div>
</div>
</div>
</div>
<script>
function getqrcode(){
	var getvcurl='login.php?do=getqrcode&r='+Math.random(1);
	$.get(getvcurl, function(d) {
		if(d.code ==0){
			$('#qrimg').attr('sign',d.sign);
			$('#qrimg').attr('link',d.link);
			$('#qrimg').html('<img id="qrcodeimg" onclick="getqrcode()" src="https://'+d.imgurl+'" title="点击刷新">');
			$('#login').show();
			$('#loginmsg').html('请使用<a href="http://xbox.m.baidu.com/mo/" target="_blank" rel="noreferrer">手机百度App</a>扫码登录');
			if( /Android|SymbianOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini|Windows Phone|Midp/i.test(navigator.userAgent) && navigator.userAgent.indexOf("QQ/") == -1) {
				$('#mobile').show();
			}
			if($('#qrimg').attr('lock')==undefined){
				setTimeout(qrlogin,2000);
				setInterval(loginload,1000);
			}
		}else{
			alert(d.msg);
		}
	}, 'json');
}
function qrlogin(){
	$('#qrimg').attr('lock','true');
	var sign=$('#qrimg').attr('sign');
	if(sign=='')return;
	var loginurl="login.php?do=qrlogin";
	$.ajax({
		type: "POST",
		url: loginurl,
		async: true,
		dataType: 'json',
		timeout: 15000,
		data: "sign="+sign+"&r="+Math.random(1),
		cache:false,
		success: function(data,status) {
			if(data.code ==0){
				$('#login').hide();
				showresult(data);
			}else{
				qrlogin();
			}
		},
		error: function(error) {
			qrlogin();
		}
	});
	
}
function loginload(){
	var load=document.getElementById('loginload').innerHTML;
	var len=load.length;
	if(len>2){
		load='.';
	}else{
		load+='.';
	}
	document.getElementById('loginload').innerHTML=load;
}
function showresult(arr){
	$('#load').html('<div class="alert alert-success">登录成功！'+decodeURIComponent(arr.displayname)+'</div><div class="input-group"><span class="input-group-addon">用户UID</span><input id="uid" value="'+arr.uid+'" class="form-control" /></div><br/><div class="input-group"><span class="input-group-addon">用户名</span><input id="user" value="'+arr.user+'" class="form-control"/></div><br/><div class="input-group"><span class="input-group-addon">BDUSS</span><input id="bduss" value="'+arr.bduss+'" class="form-control"/></div><br/><div class="input-group"><span class="input-group-addon">PTOKEN</span><input id="ptoken" value="'+arr.ptoken+'" class="form-control"/></div><br/><div class="input-group"><span class="input-group-addon">STOKEN</span><input id="stoken" value="'+arr.stoken+'" class="form-control"/></div>');
}
function mloginurl(){
	var url = $('#qrimg').attr('link');
	window.location.href='baiduboxapp://v1/easybrowse/open?upgrade=1&type=video&newbrowser=1&url='+encodeURIComponent(url);
}
$(document).ready(function(){
	getqrcode();
	$('#submit').click(function(){
		qrlogin();
	});
});
</script>
</body>
</html>